﻿@model QuanLySanXuat.Models.OrderProcessFormModels
@{
    ViewBag.Title = "Lệnh sản xuất";
}
<link href="@Url.Content("~/ContentTMT/dateui.css")" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#EndDate").datepicker();
            $("#StartDate").datepicker();
            $(".SubprocessStartDate").datepicker();
            $(".SubprocessEndDate").datepicker();
           
            $("#EndDate").datepicker("option", "dateFormat", "dd/mm/yy");
            $("#StartDate").datepicker("option", "dateFormat", "dd/mm/yy");
            $(".SubprocessStartDate").datepicker("option", "dateFormat", "dd/mm/yy");
            $(".SubprocessEndDate").datepicker("option", "dateFormat", "dd/mm/yy");
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#CheckValid').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                Code: {
                    validators: {
                        notEmpty: {
                            message: 'Mã không để trống'
                        }
                    }
                },
                OrderID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn mã sản phẩm'
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            $("#EndDate").datepicker("option", "dateFormat", "mm/dd/yy");
            $("#StartDate").datepicker("option", "dateFormat", "mm/dd/yy");
            $(".SubprocessStartDate").datepicker("option", "dateFormat", "mm/dd/yy");
            $(".SubprocessEndDate").datepicker("option", "dateFormat", "mm/dd/yy");
            // Use Ajax to submit form data
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "OrderProcess")',
                async: false,
                cache: false,
                data: $('#CheckValid').serialize(),
                success: function (result) {
                    location.href = '@Url.Action("Index", "OrderProcess")'
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
</script>
<div id="breadcrumb">
    <div class="container">
        <div id="con_top">
            <div class="c_container">
                <h3>Thực hiện sản xuất</h3>
            </div>
        </div>
    </div>
</div>
<form class="form-horizontal" role="form" id="CheckValid" style="margin-top: 10px;">
    @if (Model == null)
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Số ký hiệu (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" />
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh sản xuất(*)</label>
                <div class="col-sm-8">
                       <input type="hidden" id="HOrderID" name="HOrderID" />
                    @Html.DropDownList("OrderID", new SelectList(ViewData["Order"] as IEnumerable<Data.Models.Order>, "ID", "Code"), "Chọn lệnh sản xuất", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày bắt đầu</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="StartDate" name="StartDate">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày kết thúc</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="EndDate" name="EndDate">
                    </div>
                </div>
            </div>

        </div>
        <div class="col-sm-6">

            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Mẫu sản phẩm</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="ProductModelID" name="ProductModelID">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="Quantity" name="Quantity">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-3 control-label">Ghi chú</label>
                <div class="col-sm-8">
                    <textarea id="Note" name="Note" class="form-control" rows="5" placeholder="Mô tả" ></textarea>
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Số ký hiệu (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" value="@Model.ID"/>
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code" value="@Model.Code">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh sản xuất(*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="HOrderID" name="HOrderID"  value=" @Model.OrderID"/>
                    @Html.DropDownList("OrderID", new SelectList(ViewData["Order"] as IEnumerable<Data.Models.Order>, "ID", "Code", @Model.OrderID), "Chọn lệnh sản xuất", new { @class = "form-control",@disabled="true" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày bắt đầu</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="StartDate" name="StartDate" value="@Convert.ToDateTime(@Model.StartDate).ToShortDateString()">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày kết thúc</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="EndDate" name="EndDate" value="@Convert.ToDateTime(@Model.EndDate).ToShortDateString()">
                    </div>
                </div>
            </div>

        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Mẫu sản phẩm</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="ProductModelID" name="ProductModelID" value="@Model.ProductModelID">
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Quantity" name="Quantity" value="@Model.Quantity">
                </div>
            </div>
            <div class="form-group">
                <label for="Description" class="col-sm-3 control-label">Ghi chú</label>
                <div class="col-sm-8">
                    <textarea id="Note" name="Note" class="form-control" rows="5" placeholder="Mô tả">@Model.Note</textarea>
                </div>
            </div>
        </div>
    }
    <div class="form-group">
        <div class="c_container col-sm-10 col-sm-offset-1" id="processDetail">
            @{Html.RenderPartial("_OrderProcessDetail", Model);}
        </div>
    </div>
</form>
<script type="text/javascript">
    $(document).ready(function () {
        $("#OrderID").change(function () {
            if (this.value != "") {
                $("#HOrderID").val(this.value);
                GetDetail(this.value);
            }
        });
    });
    function GetDetail(element) {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetDetail", "OrderProcess")',
            async: false,
            cache: false,
            data: { ID: element },
            success: function (result) {
                $("#processDetail").html(result);
                $('#ProductModelID').prop('disabled', true);
                //$("#HOrderID").html(element);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });
    }
</script>
